home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / ckcd11.zip / CKCD.C < prev    next >
Text File  |  1989-09-14  |  2KB  |  70 lines

  1. /*
  2.  * C K C D . C
  3.  *
  4.  * Author: Scott Coleman, SysOp
  5.  *         Xanadu BBS
  6.  *         217/384-2127
  7.  *         FIDOnet: 1:233/69.0
  8.  *         Internet: coleman@f69.n233.z1.fidonet.org
  9.  *
  10.  * Written: 2/19/89
  11.  *
  12.  * Last Updated: 9/14/89
  13.  *
  14.  * Description: Checks the status of the carrier detect (RLSD) line for
  15.  *     the serial port specified on the command line. The program exits
  16.  *     with an exit code reflecting the state of the RLSD line:
  17.  *         ERRORLEVEL 2 == Error in processing
  18.  *         ERRORLEVEL 1 == CD is high
  19.  *         ERRORLEVEL 0 == CD is low
  20.  *
  21.  * Usage: ckcd [1 | 2]
  22.  *     where 1 == COM1:
  23.  *           2 == COM2:
  24.  *
  25.  */
  26.  
  27. #include <dos.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30.  
  31. /* bitmask for carrier detect line */
  32. #define RLSD 0x80
  33. #define VERSION "1.1"
  34.  
  35. void main(int argc, char *argv[])
  36. {
  37. int port = 0;  /* port number to check, default COM1: */
  38. union REGS r;  /* input registers for BIOS call */
  39.  
  40.     /* blatant BBS plug */
  41.     fprintf(stderr, "ckcd version %s  Copyright (C) 1989 Xanadu Consulting  All Rights Reserved.\n", VERSION);
  42.     fprintf(stderr, "Call Xanadu BBS  217/384-2127  1:233/69.0\n\n");
  43.  
  44.     /* check for optional argument */
  45.     if (argc == 2) {
  46.     port = atoi(argv[1]) - 1;  /* get desired com port number */
  47.     if (port < 0 || port > 1) {
  48.         fprintf(stderr, "Usage: %s [1 | 2]\n", argv[0]);
  49.         exit (2);
  50.         }
  51.     }
  52.  
  53.     /* check specified port for carrier */
  54.     fprintf(stderr, "Checking for carrier on COM%d:\n", port+1);
  55.     r.h.ah = 3;  /* get serial port status */
  56.     r.x.dx = port;
  57.     int86(0x14, &r, &r);
  58.     if (r.h.ah & RLSD) {  /* carrier detected? */
  59.     fprintf(stderr, "Carrier detected on COM%d:\n", port+1);
  60.     exit (1);
  61.     }
  62.     else {
  63.     fprintf(stderr, "No carrier on COM%d:\n", port+1);
  64.     exit (0);
  65.     }
  66. }
  67.  
  68.  
  69.  
  70.